﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Diagnostics;

namespace BibMan.model.database {
    class DatabaseLoader {

        public static Database Load(String filename) {
            XmlSerializer serializer = new XmlSerializer(typeof(Database));
            TextReader textReader = new StreamReader(filename);
            Database db = (Database)serializer.Deserialize(textReader);
            textReader.Close();
            return db;
        }

        public static void Save(Database references, String filename) {
            XmlSerializer serializer = new XmlSerializer(typeof(Database));
            TextWriter textWriter = new StreamWriter(filename);
            serializer.Serialize(textWriter, references);
            textWriter.Close();
        }

        public static void SaveAsBibTex(Database references, String fileName) {
            using (StreamWriter output = new StreamWriter(fileName)) {
                output.Write(references.ToBibTex());
            }
        }
    }
}
